package com.power.powercash.report;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author f6036477
 */
public class Field {

	private Object obj;

	protected Object ret;

	protected Class rtype;

	private List<Info> infos;


	public Field() {
		obj = ret = null;
		infos = new ArrayList<Info>();
	}


	public Field(Object obj) {
		this.obj = obj;
		infos = new ArrayList<Info>();
	}


	public List<Info> infos() {
		return infos;
	}


	public void addInfo(Class type, String getmethod, Class retType) {
		infos.add(new Info(type, getmethod, retType));
	}


	public void setInfos(List<Info> infos) {
		this.infos = infos;
	}


	public Object getReturn() {
		return ret;
	}


	public Class getReturnType() {
		return rtype;
	}


	public <T> T castReturn() {
		try {
			return (T) rtype.cast(ret);
		} catch(Exception ex) {
			//ex.printStackTrace();
			return null;
		}
	}


	public void setObject(Object o) {
		obj = o;
	}


	public Object getObject() {
		return obj;
	}


	public Class getType() {
		if(infos == null || infos.isEmpty()) return null;
		return infos.get(0).getType();
	}

}
